package servlet.comm;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import factory.comm.TitleDAOFactory;
import vo.comm.Title;

public class DeleteTitleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public DeleteTitleServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String titleid=request.getParameter("titleid");
		Title title=new Title();
		title.setTitleid(titleid);
		try {
			if(TitleDAOFactory.getITitleDAOInstance().doDelete(title)){
				response.sendRedirect("title/delete_success.jsp");
			}
			else{
				response.sendRedirect("title/delete_failure.jsp");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String titleid=request.getParameter("titleid");
		String titlename=request.getParameter("titlename");
		Title title=new Title();
		title.setTitleid(titleid);
		title.setTitlename(titlename);
		response.setContentType("text/html; charset=UTF-8");
		try {
			if(TitleDAOFactory.getITitleDAOInstance().doDelete(title)){
				response.sendRedirect("title/delete_success.jsp");
			}
			else{
				response.sendRedirect("title/delete_failure.jsp");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
